package can.bishe.modules.senic.service.impl;

import can.bishe.common.utils.PageUtils;
import can.bishe.common.utils.Query;
import can.bishe.modules.senic.dao.SenicInfoDao;
import can.bishe.modules.senic.entity.SenicInfoEntity;
import can.bishe.modules.senic.service.SenicInfoService;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;


@Service("senicInfoService")
public class SenicInfoServiceImpl extends ServiceImpl<SenicInfoDao, SenicInfoEntity> implements SenicInfoService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        EntityWrapper ew = new EntityWrapper<SenicInfoEntity>();
        String senicName = (String) params.get("senicName");
        if(senicName != null) {
            ew.like("senic_name",senicName);
        }
        Page<SenicInfoEntity> page = this.selectPage(
                new Query<SenicInfoEntity>(params).getPage(),
                ew
        );

        return new PageUtils(page);
    }

	@Override
	public String SavaImgfile(MultipartFile file) {

        if (file.isEmpty()){
            return "未选择文件";
        }
        String filename = file.getOriginalFilename(); //获取上传文件原来的名称
        String filePath = "./coordination-admin/src/main/resources/statics/img/";
        File temp = new File(filePath);
        if (!temp.exists()){
        	System.out.println("目录不存在");
            temp.mkdirs();
        }
 
        File localFile = new File(filePath+filename);
        try {
            file.transferTo(localFile); //把上传的文件保存至本地
            System.out.println(file.getOriginalFilename()+" 上传成功");
        }catch (IOException e){
            e.printStackTrace();
            return "读写失败";
        }finally {
        	
        }
 
        return filename;
	}

	@Override
	public List<SenicInfoEntity> recomList(Integer nums) {

		List<SenicInfoEntity> recommandList = this.baseMapper.getRecomList(nums);
		return recommandList;
	}

	@Override
	public List<SenicInfoEntity> allInfoList(String senicName, String placeName) {

		List<SenicInfoEntity> allInfodataList = this.baseMapper.getAllInfoList(senicName, placeName);
		return allInfodataList;
	}

	@Override
	public List<String> allPlaceInfoList() {

		List<String> allPlaceinfoLists = this.baseMapper.getAllPlaceInfoList();
		return allPlaceinfoLists;
	}

    @Override
    public List<SenicInfoEntity> getSearchList(Map<String, String> params) {

    	String senicName = params.get("senicName");
    	String senicPlace = params.get("senicPlace");
        List<SenicInfoEntity> searchList = this.baseMapper.getSearchList(senicName,senicPlace);
        return searchList;
    }

	@Override
	public SenicInfoEntity getSenicInfo(Long senicId) {
		// TODO Auto-generated method stub
		SenicInfoEntity resdata = this.baseMapper.getSenicInfo(senicId);
		return resdata;
	}

}
